package tt.dz.egobus.servicemanager.business.filter;

import tt.dz.egobus.servicemanager.business.distance.PointFilter;
import tt.dz.egobus.servicemanager.business.point.BusPoint;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Anson
 * @date 17-8-8
 * @name 过滤器链
 * @since 1.0.6
 */
public class PointChainFilter implements PointFilter {

    private List<PointFilter> chains = new ArrayList<PointFilter>();

    @Override
    public boolean isFilter(BusPoint point) {
        if (chains.isEmpty()) {
            return true;
        }

        for (PointFilter pointFilter : chains) {
            if (!pointFilter.isFilter(point)) {
                return false;
            }
        }
        return true;
    }


    public void add(PointFilter f) {
        if (f != null) {
            this.chains.add(f);
        }
    }

    public void remove(PointFilter f) {
        if (f != null) {
            this.chains.remove(f);
        }
    }
}
